package com.example.demo.Controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.session.StandardSession;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2023-01-05
 * Time: 15:52
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @RequestMapping("/login")
    public boolean login(String username, String password, HttpServletRequest request, HttpServletResponse response){
        //非空判断
        if(StringUtils.hasLength(username) && StringUtils.hasLength(password)){
            //判断用户名密码的正确性
            if( username.equals("admin") && password.equals("123456")){
                HttpSession session = request.getSession();
                session.setAttribute("userinfo",username);
                session.setAttribute("password",password);
                return true;
            }else{
                return false;
            }
        }
        return false;
    }

    @RequestMapping("/reg")
    public String reg(String username, String password){
        System.out.println("执行注册功能");
        return "执行注册功能";
    }

    @RequestMapping("getInfo")
    public String getInfo(){
        log.info("执行了getInfo方法");
        return "执行了getInfo方法";
    }
}
